package com.mt.operation.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.common.constants.BaseErrorConstants;
import com.mt.operation.api.service.ICustomerPopupService;
import com.mt.operation.entity.CustomerPopupEntity;
import com.mt.operation.service.model.CustomerPopupServiceModel;

@Service
public class CustomerPopupServiceImpl implements ICustomerPopupService {

    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CustomerPopupServiceImpl.class);

    @Autowired
    private CustomerPopupServiceModel customerPopupServiceModel;

    public ServiceResult<CustomerPopupEntity> findInfo(Map<String, Object> params) {
        // 查询用户信息
        ServiceResult<CustomerPopupEntity> result = null;
        // 该参数标识前段是否需要权限数据
        try {
            result = customerPopupServiceModel.selectInfo(params);
        } catch (Exception e) {
            LOGGER.error("[CustomerPopupServiceImpl][findInfo]：query findInfo occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询详情错误");
        }
        return result;
    }

    public ServiceResult<List<CustomerPopupEntity>> findList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        ServiceResult<List<CustomerPopupEntity>> result = new ServiceResult<List<CustomerPopupEntity>>();
        try {
            result = customerPopupServiceModel.selectList(params, pagerInfo);
        } catch (Exception e) {
            LOGGER.error("[CustomerPopupServiceImpl][findList]：query findList occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "查询列表错误");
        }

        return result;
    }

    public ServiceResult<Integer> doInsert(CustomerPopupEntity customerPopupEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = customerPopupServiceModel.insert(customerPopupEntity);
        } catch (Exception e) {
            LOGGER.error("[CustomerPopupServiceImpl][doInsert]：query doInsert occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "创建信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdateRelate(CustomerPopupEntity customerPopupEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = customerPopupServiceModel.updateRelate(customerPopupEntity);
        } catch (Exception e) {
            LOGGER.error("[CustomerPopupServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "编辑信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doDeleteById(Integer customerPopupId) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = customerPopupServiceModel.deleteByPrimaryKey(customerPopupId);
        } catch (Exception e) {
            LOGGER.error("[CustomerPopupServiceImpl][doDeleteById]：query doDeleteById occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "删除信息错误");
        }
        return result;
    }

    public ServiceResult<Integer> doUpdate(CustomerPopupEntity customerPopupEntity) {
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        try {
            result = customerPopupServiceModel.updateByPrimaryKeySelective(customerPopupEntity);
        } catch (Exception e) {
            LOGGER.error("[CustomerPopupServiceImpl][doUpdate]：query doUpdate occur exception", e);
            result.setError(BaseErrorConstants.ERROR_CODE_SERVICE_CONTROLLER, "更新信息错误.");
        }
        return result;
    }

}
